package com.jxf.demo.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class StraightLine {

    /**
     * 起点坐标
     */
    private Coordinate start;
    /**
     * 终点坐标
     */
    private Coordinate end;
    /**
     *
     */
    private BigDecimal radius;
    private BigDecimal c;


    public static StraightLine polygon(Coordinate start, Coordinate end) {
        return StraightLine.builder()
                .start(start)
                .end(end)
                .radius(BigDecimal.ZERO)
                .c(BigDecimal.ONE)
                .build();
    }

    public static StraightLine circle(Coordinate start, Coordinate end, BigDecimal radius) {
        return StraightLine.builder()
                .start(start)
                .end(end)
                .radius(radius)
                .c(BigDecimal.ONE)
                .build();
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Coordinate {

        private static final int SCALE = 1;
        private BigDecimal x;
        private BigDecimal y;

        public static Coordinate getPointCoordinate(BigDecimal x,BigDecimal y){
            return new Coordinate(x.setScale(SCALE, RoundingMode.HALF_UP),y.setScale(SCALE, RoundingMode.HALF_UP));
        }

        public static Coordinate getPointCoordinate(double x,double y){
            return new Coordinate(new BigDecimal(String.valueOf(x)),new BigDecimal(String.valueOf(y)));
        }

    }

}
